#ifndef METANET_H
#define METANET_H

#include <stdint.h>
#include <stddef.h>

#define PTYPE_TEXT 0
#define PTYPE_RESPONSE 1
#define TYPE_MULTICAST 2
#define PTYPE_CLIENT 3
#define PTYPE_SYSTEM 4
#define PTYPE_HARBOR 5
#define PTYPE_SOCKET 6
#define PTYPE_ERROR 7

#define PTYPE_RESERVED_QUEUE 8
#define PTYPE_RESERVED_DEBUG 9
#define PTYPE_RESERVED_LUA 10
#define PTYPE_RESERVED_SNAX 11

#define PTYPE_TEST 22

#define PTYPE_TAG_DONTCOPY 0x10000
#define PTYPE_TAG_ALLOCSESSION 0x20000

struct metanet_context;

void metanet_error(struct metanet_context *context, const char *msg, ...);
const char *metanet_command(struct metanet_context *context, const char *cmd, const char *param);

uint32_t metanet_queryname(struct metanet_context *context, const char *name);
uint32_t metanet_service_key(struct metanet_context *ctx, const char *param);

int metanet_send(struct metanet_context *ctx, uint32_t source, uint32_t destination, int type,  int session,  void *msg,  size_t sz);
int metanet_sendname(struct metanet_context *ctx, uint32_t source, const char *destination, int type, int session, void *msg, size_t sz);

typedef int (*metanet_cb)(struct metanet_context *ctx, void *cb_ud, int type, int session, uint32_t source, const void *msg, size_t sz);
void metanet_callback(struct metanet_context *ctx, void *ud, metanet_cb cb);

uint32_t metanet_current_handle(void);

uint64_t metanet_now(void);

#endif // !METANET_H